package com.soft.admin.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.soft.admin.dto.RuleDTO;
import com.soft.admin.service.RuleService;
import com.soft.support.PageParam;

@Controller
@RequestMapping(value = "/admin/rule.do")
public class RuleController extends BaseController {
	private RuleService ruleService;

	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request, RuleDTO params, 
			PageParam page) throws IOException {
		String res = this.ruleService.get(params, page);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextochannel")
	public String getChannel(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.ruleService.getChannel();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextouser")
	public String getUser(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.ruleService.getUser();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextoimg")
	public String upload(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.ruleService.upload(request);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextodetail")
	public String detail(HttpServletResponse response, HttpServletRequest request, 
			Integer id) throws IOException {
		String res = this.ruleService.getFile(id);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "add")
	public String add(HttpServletResponse response, HttpServletRequest request, 
			RuleDTO params, String[] sources) throws IOException {
		String res = this.ruleService.addOrEdit(request, params, sources);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "edit")
	public String edit(HttpServletResponse response, HttpServletRequest request, 
			RuleDTO params, String[] sources) throws IOException {
		String res = this.ruleService.addOrEdit(request, params, sources);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "remove")
	public String remove(HttpServletResponse response, HttpServletRequest request, 
			Integer id) throws IOException {
		String res = this.ruleService.remove(request, id);
		response.getWriter().print(res);
		return null;
	}
	
	@Autowired
	public void setRuleService(RuleService ruleService) {
		this.ruleService = ruleService;
	}
	
}
